"use strict";
define(function (require, exports, module) {
    let config = require('../config'); 
    let Service = require('core/service').Service;

    class UserService extends Service {
        constructor() {
            super(config.rootUrl + "/user");
        }

        findByAccount(account) {

        }

        validate(account, userNo) {
            var result = false;
            $.ajax(
                {
                    url: config.rootUrl + "/user/validate",
                    async: false,
                    data: {account, userNo}
                }).then(d=>result = d == 0 ? true : false);
            return result;
        }
        getUserData(userNo,type,code){
            return $.get(config.rootUrl+"/user/datavalue",{userNo,type,code});
        }
        
        getUserData2(userNo,type){
        	 var result = false;
             $.ajax(
                 {
                     url: config.rootUrl+"/user/datavalue",
                     async: false,
                     data: {userNo,type}
                 }).then(d=>result = d);
             return result;
        }
        assignRoles(userNo, roles) {
            return $.xpost(config.rootUrl + "/user/assign/role/" + userNo, roles);
        }
        assignData(userNo,datas){
            return $.post(config.rootUrl+"/user/assignData?userNo=" + userNo,
                 { datas:JSON.stringify(datas)}
            );
        }

        /**
         * 分配用户模块
         * @param userNo
         * @param moduleNo
         * @param operations
         */
        assignUserModule(userNo,moduleNo,operations,status){
            return $.post(config.rootUrl+"/user/assign/module" ,
                {userNo,moduleNo, operations,status}
            );
        }

        assignUserModules(datas){
            return $.post(config.rootUrl+"/user/assign/modules" ,
                { datas:JSON.stringify(datas)}
            );
        }

        update(params) {
            var self = this;
            return $.post(this.url + "/updateuser", params);
        }
        create(params) {
            var self = this;
            return $.post(this.url + "/createuser", params);
        }

        getMenu(params){
        	var url = `${config1.rootUrl}/personal/menu/tree`;
        	return $.get(url, params);
        }
        
        searchRole(userNo,name){
        	var url=config.rootUrl + '/userrole/query?userNo='+userNo + '&name=' + name;
        	return $.get(url);
        }
        
        searchAll(userNo1,name){
        	var url = config.rootUrl + '/userrole/query?name='+name + '&userNo=' +userNo1 ;
        	return $.get(url);
        }

    }

    class detailService extends Service {
        constructor() {
            super(config.rootUrl + "/userdetail");
        }

        saveDetail(params) {
            var self = this;
            return $.post(this.url + '/create', params);
        }
    }

    module.exports = UserService;
});